package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.TowerViolation;
import com.hengxinguotong.zhihuichengjian.treeview.RecyclerAdapter;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @CopyRight 恒信国通信息科技
 * @Author WuLei
 * @Date 2019/2/25
 *
 * 塔吊详情违章列表适配器
 */

public class TowerDataViolationListAdapter extends RecyclerAdapter<TowerViolation, TowerDataViolationListAdapter.TowerDataViolationListViewHolder> {

    public TowerDataViolationListAdapter(Context context, List<TowerViolation> dataList) {
        super(context, dataList);
    }

    @Override
    public TowerDataViolationListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_tower_data_list_violation, null);
        return new TowerDataViolationListViewHolder(view);
    }

    @Override
    public void onBindViewHolder(TowerDataViolationListViewHolder holder, int position) {
        holder.bindData(position);
    }

    public class TowerDataViolationListViewHolder extends RecyclerAdapter.BaseViewHolder<TowerViolation>{
        @BindView(R.id.tower_weight_tv)
        HXTextView towerWeightTv;
        @BindView(R.id.tower_weight_percent_tv)
        HXTextView towerWeightPercentTv;
        @BindView(R.id.create_time_tv)
        HXTextView createTimeTv;

        public TowerDataViolationListViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void bindData(int position) {
            final TowerViolation towerViolation = dataList.get(position);
            towerWeightTv.setText("最大吊重：" + towerViolation.getMaxWeight() + "KG");
            towerWeightPercentTv.setText("最大负荷：" + towerViolation.getMaxFh() + "%");
            createTimeTv.setText(towerViolation.getAcquisitionTime());
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onClickListener.onClick(towerViolation);
                }
            });
        }
    }
}
